import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { BaseItem } from "../../common/BaseItem";
import { SPlayerItem } from "../../../../../Message/Public/SPlayerItem";
import { ItemData } from "../../../resource/info/ItemData";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GuildUtil } from "../info/GuildUtil";
import { Cache } from "../../../cache/Cache";
import { GameController } from "../../../mvc/GameController";
import { GameUI } from "../../mainUI/GameUI";
import { ModuleType } from "../../common/ModuleType";
import { FlyToNavbarTool } from "../../award/FlyToNavbarTool";
//class WarehouseExRenderer
    
    export  class WarehouseExRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            addEventListener(flash.events.MouseEvent.CLICK, this.onItemMouseClickHandler);
            return;
        }

        protected /* override */ configUI(): void
        {
            super.configUI();
            var loc1=GlobalClass.getBitmap(ImagesConst.PackItemBg);
            addChild(loc1);
            this._item = new BaseItem();
            this._item.setSize(32, 32);
            this._item.move(2, 2);
            this._item.isDragAble = false;
            this._item.isDropAble = false;
            this._item.isShowLock = true;
            addChild(this._item);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            if (arg1 == null) 
            {
                this._playerItem = null;
                this._item.itemData = null;
            }
            else 
            {
                this._playerItem = arg1 as SPlayerItem;
                this._item.itemData = new ItemData(this._playerItem.itemCode);
            }
            return;
        }

        /* internal  */onItemMouseClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._playerItem) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GuildWarehouseExMoveItem, {"uid": this._playerItem.uid, "allMove": false}));
                if (GuildUtil.isLeader(Cache.instance.guild.myGuildInfo)) 
                {
                    this.flyIconToGuild();
                }
            }
            return;
        }

        public flyIconToGuild(): void
        {
            if (this._playerItem == null || this._item == null) 
            {
                return;
            }
            var loc1=new Object /* flash.geom.Point */(this._item.x, this._item.y);
            var loc2=(GameController.gameui.view as GameUI).getNavbarIconGlobalPoint(ModuleType.Guild);
            FlyToNavbarTool.flyToAnyPoint(this._item.bitmapdata, localToGlobal(loc1), loc2, this.flyBitMapEnd);
            return;
        }

        /* internal  */flyBitMapEnd(arg1: Object /* flash.display.Bitmap */): void
        {
            if (arg1 && arg1.parent) 
            {
                arg1.parent.removeChild(arg1);
                arg1 = null;
            }
            return;
        }

        /* internal */ /* var */_item: BaseItem;

        /* internal */ /* var */_playerItem: SPlayerItem;
    }
